<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/main.css">
    <link rel="stylesheet" href="../css/jquery-ui.css">
    <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
    <title>Document</title>
    <style>
        .uploadFile{
            margin: 0;
            padding: 0;
            border: none;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="box_border">
        <div class="box_top"><b class="pl15">数据筛选</b></div>
        <div class="box_center pt10 pb10" style="padding-left: 35%;">
            <table class="form_table" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><input type="text" id="searchText" name="search" class="input-text lh30" size="40"></td>
                    <td>
                        <span class="fl "   >
                    <div class="select_border ">
                        <div class="select_containers ">
                            <select name="" class="select" id="sectionSelect" >
                                <option value="0">全部人员</option>
                            </select>
                        </div>
                    </div>
                </span>
                    </td>
                    <td><input type="button" value="搜索" class="ext_btn ext_btn_submit" onclick="searchUserData()"></td>
                    <td><input type="button" value="增加"  class="ext_btn ext_btn_submit" onclick="addUserData()"></td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="box">
    <div class="box_border">
        <div class="box_top">
            <b class="pl15">人员信息</b>
        </div>

        <div style="clear: both;"></div>
        <div class="mt10">
            <div id="table" class="mt10">
                <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                    <table id="approval_info1" width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                        <tr>
                            <th class="td_center"  style="width: 5%;"><input type="checkbox" name="checkAll" onclick="checkBoxChecked(this)"></th>
                            <!--<th class="td_center"  style="width: 5%;">序号</th>-->
                            <th class="td_center" >账号</th>
                            <th class="td_center" >姓名</th>
                            <!--<th class="td_center" >部门</th>-->
                            <th class="td_center" >职别</th>
                            <!--<th class="td_center" >职位</th>-->
                            <th class="td_center" >可选操作</th>
                        </tr>
                        <tbody id="approval_info">
                        </tbody>
                    </table>
                    <div class="page mt10 fl">
                        <a class="ext_btn del mt10" onclick="batchDelete()" ><span class="del" ></span>批量删除</a>
                        <form  id='FileForm'method="post" action="http://192.168.0.107/gongan1/GongAn/admin/Admin/AdminPhpExcel.php" enctype="multipart/form-data" style="display: inline-block">
                            <input  type="file" name="file_stu"  style="display: inline-block;border:0; padding:0; margin:0; "/>
                            <input class="ext_btn add  mt10" type="button"  value="批量导入" style="display: inline-block" onclick="return checkFile(this.form)" />
                        </form>
                        <!--<a class="ext_btn del mt10" ><span class="del" ></span>删除全部</a>-->
                    </div>
                    <div class="page  fr" style="margin-top: -10px;">
                        <div class="pagination">
                            <ul id="ul">
                                <li class="first-child " id="li1"><a onclick="firstLastPage(0)">首页</a></li>
                                <li class="" id="li2"><a onclick="upDownPage(-1)">上一页</a></li>
                                <li class="" id="li3"><a onclick="upDownPage(1)">下一页</a></li>
                                <li class="last-child " id="li4"><a onclick="firstLastPage(1)">末页</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dialog" title="" style="display: none;">
    <form name="from1" >
        <div class="pb10 mb15 "> <div style="display: inline-block;width:46px;text-align: right;">身份证:</div>
            <input type="text" name="user_number" class="input-text lh30 ml " id="user_number" size="30" onkeyup="value=value.replace(/[^\d]/g,'')" ><span style="color:red;font-size: 20px;">&nbsp;*</span></div>
        <div class="pb10 mb15"> <div style="display: inline-block;width:46px;text-align: right;" >姓名:</div>
            <input type="text" name="user_name" class="input-text lh30 ml" id="user_name" size="30"   ><span style="color:red;font-size: 20px;">&nbsp;*</span></div>
        <div class="pb10 mb15"> <div style="display: inline-block;width:46px;text-align: right;"  >密码:</div>
            <input type="text" name="user_pwd" class="input-text lh30 ml" id="user_pwd" size="30"   ><span style="color:red;font-size: 20px;">&nbsp;*</span></div>
        <div class="pb10 mb15"> <div style="display: inline-block;width:46px;text-align: right;"   >公务卡:</div>
            <input type="text" name="card_number" class="input-text lh30 ml" size="30" id="card_number" onkeyup="value=value.replace(/[^\d]/g,'')"></div>
        <div class="pb10 mb15"> <div style="display: inline-block;width:46px;text-align: right;" >级别:</div>
            <select name="executive_level" class="select ml" selected >
                <option value="1">办事员(警员)职</option>
                <option value="2">科员(警长)职</option>
                <option value="3">科(局)级副职</option>
                <option value="4">科(局)级正职</option>
                <option value="5">处(局)级副职</option>
                <option value="6">处(局)级正职</option>
                <option value="7">厅(局)级副职</option>
                <option value="8">厅(局)级正职</option>
            </select>
            </div>
        <!--<div class="pb10 mb15"><div style="display: inline-block;width:100px;text-align: right;"  > 旺季时间:</div>-->
        <!--<input type="text" name="fire_time" class="input-text lh30 ml" size="30" id="card_number" ></div>-->
        <!--<input type="button" id="back" value="删除" class="ext_btn ext_btn_submit">-->
        <!--<input type="submit" id="save" value="保存" class="ext_btn ext_btn_submit">-->
    </form>
</div>
<div id="dialogSign" style="text-align: center;display: none;">
    <iframe class="uploadFile" id="UploadFile" height="50" src="">
    </iframe>
</div>
<div id="dialogA" style="text-align: center;display: none;"></div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/config.js"></script>
<script type="text/javascript">
    var selectWay=null;
    var searchWay=null;
    //初始化函数 获取部门加载下拉栏sectionSelect
    function createSectionSelect(){
        var phpUrl=url+'admin/User/AllSectionGetData.php';
        $.ajax({
            url:phpUrl,
            type: "POST",
            success:function(sectionData){
//                alert(sectionData);
//                alert(sectionData);
                sectionData=JSON.parse(sectionData);
                for(var i=0;i<sectionData.length;i++)
                    $("#sectionSelect").append('<option value="'+sectionData[i].section_ID+'">'+sectionData[i].section_name+'</option>');
            }
        });
    }

    //搜索姓名获取数据
    function searchUserData(){
        $("#ul").hide();
        var phpUrl=url+'admin/User/UserGetDataByUserName.php';
        var searchText= $("#searchText").val();
        if(searchText!=''&&$("#sectionSelect").val()==0){
            searchWay=searchText;
            selectWay=null;
            $.ajax({
                url:phpUrl,
                type:"POST",
                data:{model:'search',userName:searchText},
                success:function(userData){
//                  alert(userData);
                    if(userData!='null') {
                        userData = JSON.parse(userData);
                        createTable(userData);
                        $("#approval_info1").show();
                    }else{
                        $("#approval_info1").hide();
                    }
                }
            });
        }
        else if(searchText!=''&&$("#sectionSelect").val()!=0){
            phpUrl=url+'admin/User/UserGetDataByUserNameAndSectionId.php';//UserGetDataByUserNameAndSectionId.php
            $.ajax({
                url:phpUrl,
                type:"POST",
                data:{model:'getuserDataByUserNameAndSectionId',userName:searchText,sectionId:$("#sectionSelect").val()},
                success: function (data) {
//                    alert(data);
                    data=JSON.parse(data);
                    if(data!=null){
                        createTable(data);
                        $("#approval_info1").show();
                    }else{
                        $("#approval_info1").hide();
                    }
                }
            });
        }else if(searchText==''&&$("#sectionSelect").val()!=0){

            selectUserData($("#sectionSelect").val());

        }else{
            $("#ul").show();
            $("#approval_info1").show();
            firstLastPage(0);
        }
    }
    //关闭信息栏
    function closeDialogA(){
        $("#dialogA").dialog('close');
    }
    //通过部门获取人员数据
    function selectUserData(selectValue){
        var phpUrl=url+'admin/User/UserGetDataBySectionId.php';
//      alert(selectValue);
        if(selectValue!=0){
            searchWay=null;
            selectWay=selectValue;
            $.ajax({
                url:phpUrl,
                type:"POST",
                data:{model:'getBySectionId',sectionId:selectValue},
                success:function(userData){
//                    alert(userData);
                        userData = JSON.parse(userData);
                    if(userData!=null) {
//                        alert(1);
                        createTable(userData);
                        $("#approval_info1").show();
                    }else{
                        $("#approval_info1").hide();
                    }
                }
            });
        }
    }
    //创建表格
    function createTable(tableData){
        $("#approval_info").empty();
        for(var i=0;i<tableData.length;i++){
            $("#approval_info").append(
                    '<tr><td align="center"><input type="checkbox" name="checkUserId"  onclick="checkBoxChange()" value="'+tableData[i]['user_number']+'"></td>' +
//                    '<td class="td_center  " >' +(i+1)+ '</td>'+
                    '<td class="td_center  " >' + tableData[i]['user_number'] + '</td>'+
                    '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
//                    '<td class="td_center  " >' + tableData[i]['section_name'] + '</td>'+
                    '<td class="td_center  " >' + tableData[i]['name'] + '</td>'+
//                    '<td class="td_center  " >' + tableData[i]['section_job'] + '</td>'+
                    '<td class="td_center"><a class="ext_btn modify" onclick="editUserData('+tableData[i]['user_number']+')"><span class="modify" ></span>编辑</a>'+
                    '<a class="ext_btn upload" onclick="UploadFile('+tableData[i]['user_number']+')"><span class="upload" ></span>上传签名</a>'+
                    '<a class="ext_btn del" onclick="deleteUserDataFront('+tableData[i]['user_number']+')"><span class="del" ></span>删除</a></td></tr>'
            );
    }}
    //编辑信息
    function editUserData(userNumber){
//        alert(userNumber);
        $("#user_number").addClass("disabled").attr('readonly','true');
        var phpUrl=url+'admin/User/UserGetDataByUserNumber.php';
        var titleName=null;
            $.ajax({
                url:phpUrl,
                type:"POST",
                data:{userNumber:userNumber},
                success:function(userData){
//                    alert(userData);
                    userData=JSON.parse(userData);
                    if(userData!=null) {
                        var from1=document.from1;
                        from1.user_number.value=userData.user_number;
                        titleName=from1.user_name.value=userData.user_name;
                        from1.user_pwd.value=userData.user_pwd;
                        from1.card_number.value=userData.card_number;
                        from1.executive_level.selectedIndex=userData.executive_level-1;
                        $( "#dialog" ).dialog({
                            title:titleName,
                            width:330,
                            buttons:{
                                "取消":function(){
                                    $( "#dialog" ).dialog('close');
                                },
                                "保存":function() {
                                    var user_number = from1.user_number.value;
                                    var user_name = from1.user_name.value;
                                    var user_pwd = from1.user_pwd.value;
                                    var card_number = from1.card_number.value;
                                    var executive_level = from1.executive_level.selectedIndex + 1;
                                    if (user_number == '' || user_name == '' || user_pwd == '') {DialogInfo("数据未填完整!"); setTimeout('closeDialogInfo()',1000)}
                                    else {
                                        phpUrl = url + "admin/User/UserUpdateData.php";
                                        $.ajax({
                                            url: phpUrl,
                                            type: "POST",
                                            data: {
                                                model: 'update',
                                                user_number: user_number,
                                                user_name: user_name,
                                                user_pwd: user_pwd,
                                                card_number: card_number,
                                                executive_level: executive_level
                                            },
                                            success: function (userData) {
//                                            alert(userData);
                                                var state = JSON.parse(userData);
                                                if (state['state'] == 1) {
                                                    document.getElementById('dialogA').innerHTML = '保存成功！';
                                                    getUserPageCount();
                                                    $("#dialogA").dialog({
                                                                resizable: false,
                                                                title: "信息",
                                                                modal: true,
                                                                buttons: {
                                                                    '确定': function () {
                                                                        $("#dialog").dialog('close');
                                                                        $("#dialogA").dialog('close');
//                                                                alert(searchWay+':'+selectWay);
                                                                        if (searchWay || selectWay) {
                                                                            if (searchWay) {
//                                   alert(1);
                                                                                searchUserData(searchWay);
                                                                            }
                                                                            if (selectWay) {
//                                   alert(2);
                                                                                selectUserData(selectWay);
                                                                            }
                                                                        } else {
                                                                            getUserDataLimit(curPage * 10, 10);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                    );
                                                }
                                                else {
                                                    document.getElementById('dialogA').innerHTML = "保存失败！";
                                                    $("#dialogA").dialog({
                                                                resizable: false,
                                                                title: "信息",
                                                                modal: true,
                                                                buttons: {
                                                                    '确定': function () {
                                                                        $("#dialogA").dialog('close');
//                                                                alert(searchWay+':'+selectWay);
                                                                        if (searchWay || selectWay) {
                                                                            if (searchWay) {
//                                   alert(1);
                                                                                searchUserData(searchWay);
                                                                            }
                                                                            if (selectWay) {
//                                   alert(2);
                                                                                selectUserData(selectWay);
                                                                            }
                                                                        } else {
                                                                            getUserDataLimit(curPage * 10, 10);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                    );
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        });
                    }
                }
            });
    }
    //添加数据
//    data:{model:'insert',user_number:user_number,user_name:user_name,user_pwd:user_pwd,card_number:card_number,executive_level:executive_level},
    function addUserData(){
        $("#user_number").removeClass("disabled").removeAttr('readonly');
            var from1=document.from1;
            from1.user_number.value='';
            from1.user_name.value='';
            from1.user_pwd.value='';
            from1.card_number.value='';
            from1.executive_level.selectedIndex=0;
            $( "#dialog" ).dialog({
                title:'增加人员',
                width:330,
                buttons:{
                    "取消":function(){
                        $( "#dialog" ).dialog('close');
                    },
                    "保存":function(){
                        var user_number =from1.user_number.value;
                        var user_name=from1.user_name.value;
                        var user_pwd=from1.user_pwd.value;
                        var card_number= from1.card_number.value;
                        var executive_level=from1.executive_level.selectedIndex+1;
                        if(user_number==''||user_name==''||user_pwd==''){DialogInfo("数据未填完整!"); setTimeout('closeDialogInfo()',1000)}
                        else{
                            var phpUrl = url + "admin/User/UserInsertData.php";
                            $.ajax({
                                url: phpUrl,
                                type: "POST",
                                data: {
                                    model: 'insert',
                                    user_number: user_number,
                                    user_name: user_name,
                                    user_pwd: user_pwd,
                                    card_number: card_number,
                                    executive_level: executive_level
                                },
                                success: function (userData) {
//                                    alert(userData);
                                    var state = JSON.parse(userData);
                                    if (state['state'] == 1) {
                                        DialogInfo("添加成功！");
                                        $( "#dialog" ).dialog('close');
                                        getUserPageCount();
                                    }
                                    else {
                                        DialogInfo("用户已存在或者已离职！");
                                }
                                }
                            });
                        }
                    }
                }});
    }
    //提示弹窗
    function DialogInfo(data){
        document.getElementById('dialogA').innerHTML=data;
        $("#dialogA").dialog({
                    resizable:false,
                    title: "信息",
                    modal: true,
                    buttons:{
                        '确定':function(){
                            $("#dialogA").dialog('close');
//                                                                alert(searchWay+':'+selectWay);
                            if(searchWay||selectWay) {
                                if (searchWay) {
//                                   alert(1);
                                    searchUserData(searchWay);
                                }
                                if (selectWay) {
//                                   alert(2);
                                    selectUserData(selectWay);
                                }
                            }else{
                                getUserDataLimit(curPage*10,10);
                            }
                        }
                    }
                }
        );
    }
    //关闭信息提示栏
    function closeDialogInfo(){
        $("#dialogA").dialog('close');
    }
  //  删除数据
    function deleteUserDataFront(user_number){
        document.getElementById('dialogA').innerHTML='<p style="color: red;">你确定要删除？与之相关联的其它信息也将删除！</p>';
        $("#dialogA").dialog({
            resizable:false,
            title: "信息",
            modal: true,
            buttons:{
                '取消': function () {
                    $("#dialogA").dialog('close');
                },
                '确定':function(){
                    deleteUserData(user_number);
                }
            }
        });
    }
    function deleteUserData(user_number){
//        alert(user_number);
        var phpUrl=url+"admin/User/UserDeleteData.php";
        $.ajax({
            url:phpUrl,
            type:'POST',
            data:{model:'delete',user_number:user_number},
            success:function(userData){
//                alert(userData);
                var state=JSON.parse(userData);
                if(state['state']==1)
                    document.getElementById('dialogA').innerHTML='删除成功！';
                else
                    document.getElementById('dialogA').innerHTML="删除失败！";
                getUserPageCount();
                $("#dialogA").dialog({
                            resizable:false,
                            title: "信息",
                            modal: true,
                            buttons:{
                                '确定':function(){
                                    $("#dialogA").dialog('close');
//                                  lert(searchWay+':'+selectWay);
                                    if(searchWay||selectWay) {
                                        if (searchWay) {
//                                   alert(1);
                                            searchUserData(searchWay);
                                        }
                                        if (selectWay) {
//                                   alert(2);
                                            selectUserData(selectWay);
                                        }
                                    }else{
                                        getUserDataLimit(curPage*10,10);
                                    }
                                }
                            }
                        }
                );
            }
        });
    }
  //批量删除
    function batchDelete(){
        $('input[name="checkAll"]')[0].checked=false;
        var checkBox=$('input[name="checkUserId"]');
        for(var i=0;i<checkBox.length;i++){
            if(checkBox[i].checked)deleteUserData(checkBox[i].value);
        }
    }
    //辅助批量修改全选按钮状态
    function checkBoxChange(){
        $('input[name="checkAll"]')[0].checked=false;
    }

    //判断全选按钮
    function checkBoxChecked(e){
        var checkBox=$('input[name="checkUserId"]');
        if(e.checked){
            for(var i=0;i<checkBox.length;i++){
                checkBox[i].checked=true;
            }
        }else{
            for(var i=0;i<checkBox.length;i++){
                checkBox[i].checked=false;
            }
        }
    }
    //获取页数
    var pageCounts=0;
    var curPage=0;
    function getUserPageCount(){
        var phpUrl=url+'admin/User/UserGetPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            data:{model:'getPageCount'},
            success: function (data) {
            //    alert(data);
                data = JSON.parse(data);
                if (data.state == 1) {
                    pageCounts = Math.ceil(data.data/10);
                }
            }
        });
    }
    function getUserDataLimit(n,m){
        selectWay=null;
        searchWay=null;
        var phpUrl=url+'admin/User/UserGetDataLimit.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            data:{model:'getUserDataLimit',n:n,m:m},
            success: function (data) {
                data=JSON.parse(data);
                if(data['state']==1){
//                    alert(1);
                    createTable(data.data);
//                    searchWay=
                }
            }
        });
    }
    //首尾跳页
    function firstLastPage(e){
        $("#ul li").show();
        if(pageCounts>1) {
            if (e == 0) {
                curPage = 0;
                $("#ul li").addClass("disabled");
                $("#li3").removeClass("disabled");
                $("#li4").removeClass("disabled");
            }
            else {
//      alert(pageCounts);
                curPage = pageCounts - 1;
                $("#ul li").addClass("disabled");
                $("#li1").removeClass("disabled");
                $("#li2").removeClass("disabled");
            }
        }
        getUserDataLimit(curPage * 10, 10);
    }
    //上下翻页
    function upDownPage(e){
        $("#ul li").show();
        if(pageCounts>1) {
            if (curPage >= 0 || curpage <= pageCounts - 1) {
                if (e < 0) {
                    if (curPage > 0) {
                        curPage--;
                        if (curPage > 0) $("#ul li").removeClass("disabled");
                        else {
                            $("#ul li").removeClass("disabled");
                            $("#li1").addClass("disabled");
                            $("#li2").addClass("disabled");
                        }
                    }
                } else {
                    if (curPage < pageCounts - 1) {
                        curPage++;
                        if (curPage < pageCounts - 1) $("#ul li").removeClass("disabled");
                        else {
                            $("#ul li").removeClass("disabled");
                            $("#li3").addClass("disabled");
                            $("#li4").addClass("disabled");
                        }
                    }
                }
            }
        }
        getUserDataLimit(curPage * 10, 10);
    }
    //上传文件
    function checkFile(e) {
//        alert(e.file_stu.value);
        var UserFile=e.file_stu.value.split('.');
        var UserName=UserFile[UserFile.length-1];
        UserName=UserName.toLowerCase();
        if(e.file_stu.value!=''){
            if(UserName=='xls'||UserName=='xlsx')
                e.submit();
            else{
                alert("格式不正确！ 只能上传:xls、xlsx格式");
            }
        }else{
            alert("请选择上传Excel文件！");
        }
    }
    //上传签名
    function UploadFile(e) {
        var ThisUrlArray=url.split('/');
        var thisUrl='';
        for(var i=0;i<ThisUrlArray.length-2;i++){
            thisUrl+=ThisUrlArray[i]+"/";
        }
//        alert(thisUrl);
        $("#UploadFile").attr("src","UploadFile.php?UserNumber="+e);
//        alert(url+"manager/UploadFile.php?UserNumber="+e);
        $( "#dialogSign" ).dialog({
            title: '账号：'+e+"--上传签名",
            width: 330,
            buttons: {}
        });
    }
    //网页初始化
    $(function (){
        createSectionSelect();
//        $("#approval_info1").hide();

        getUserPageCount();
//        alert(pageCount);
//        alert(pageCounts);
        if(pageCounts==1)  $("#ul li").addClass("disabled");
        firstLastPage(0);
        $("#FileForm").attr('action',url+"admin/Admin/AdminPhpExcel.php")

    });
</script>
</html>
  